<?php 
session_start();
if (!isset($_SESSION['username'])) {
	header('location:./');
}

$title = isset($_POST['title'])? $_POST['title']:"";
$tokey = isset($_POST['tokey'])? $_POST['tokey']:"";

$config['config']['title'] = $title;
$config['config']['tokey'] = $tokey;
// 将修改后的内容写回 INI 文件
$content = '';
foreach ($config as $section => $values) {
    $content .= "[$section]\n";
    foreach ($values as $key => $value) {
        $content .= "$key = $value\n";
    }
    $content .= "\n";
}
file_put_contents('config.ini', $content);




$page_keyword = isset($_POST['page_keyword'])? $_POST['page_keyword']:array();
$page_url = isset($_POST['page_url'])? $_POST['page_url']:array();

$cnt = count($page_keyword);
for ($i = 0; $i < $cnt; $i++){
    $key = $page_keyword[$i];
    $url = $page_url[$i];
    if($key=='' || $url=='') continue;
    $urls[$key] = $url;
}

// 将修改后的内容写回 INI 文件
$content = '';
foreach ($urls as $key => $value) {
    $content .= "$key = $value\n";
}
$content .= "\n";
file_put_contents('url.ini', $content);

$_SESSION['urls'] = $urls;
$_SESSION['msg'] = "提交成功，请刷新导航页查看效果。";
header('location:./');
?>